//
//  OXNavigationController.m
//  XHCoach
//
//  Created by 陈强 on 16/5/16.
//  Copyright © 2016年 com.apis. All rights reserved.
//

#import "OXNavigationController.h"
#import "NKTabBarController.h"
#import "NKTabBar.h"
#import "NKSettingController.h"

#define kColorNavBar [UIColor whiteColor]
#define kTitleFont [UIFont boldSystemFontOfSize:20]
#define kBackImage @"返回"

@interface OXNavigationController ()

@end

@implementation OXNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

+ (void)initialize {
    
    UINavigationBar *navigationBar = [UINavigationBar appearance];
    //UIBarMetricsDefault  背景图片 在横竖屏都显示
//    [navigationBar setBackgroundImage:[UIImage imageNamed:@"NavBar64"] forBarMetrics:UIBarMetricsDefault];
    [navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : kColorNavBar,NSFontAttributeName : kTitleFont}];
    
    [navigationBar setBackgroundImage:[UIImage imageNamed:@"图层-0"] forBarMetrics:UIBarMetricsDefault];
    [navigationBar setShadowImage:[UIImage new]];
    
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count > 0) {
       viewController.navigationItem.leftBarButtonItems = [self creatBackItem];
        //当push的时候隐藏tabBar
        viewController.hidesBottomBarWhenPushed = YES;
//        NKTabBarController *vc = (NKTabBarController *)viewController.tabBarController;
//        vc.aTabBar.hidden = YES;
    }
    
//    if ([viewController isKindOfClass:[NKSettingController class]]) {
//        [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"背景底图"] forBarMetrics:UIBarMetricsDefault];
//        [self.navigationBar setShadowImage:[UIImage new]];
//    }else{
//        [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"图层-0"] forBarMetrics:UIBarMetricsDefault];
//        [self.navigationBar setShadowImage:[UIImage new]];
//    }
//
//    if ([viewController isKindOfClass:[NKMiddleController class]]) {
//        //当push的时候隐藏tabBar
//        viewController.hidesBottomBarWhenPushed = YES;
//    }
    //自定义后退按钮后，手势返回上一级控制器的功能恢复
//    self.interactivePopGestureRecognizer.delegate = nil;
    [super pushViewController:viewController animated:animated];
}

- (NSArray *)creatBackItem {
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"listen_icon-back"] style:UIBarButtonItemStylePlain target:self action:@selector(backClick)];
    
    UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    fixedItem.width = 10;
    
    return @[fixedItem,backItem];
}

- (void)backClick {
    [self popViewControllerAnimated:YES];
}

//统一设置状态栏
- (UIStatusBarStyle)preferredStatusBarStyle {
    if ([self.topViewController respondsToSelector:@selector(preferredStatusBarStyle)]) {
        return [self.topViewController preferredStatusBarStyle];
    }else{
        return UIStatusBarStyleLightContent;
    }
}
@end
